﻿using Masuit.Tools;
using Masuit.Tools.Security;
using SqlSugar;

namespace sixgod.Model.User
{
    [SugarTable("Users", "用户表")]
    public class User : ModelBase
    {
        /// <summary>
        /// 名字
        /// </summary>
        [SugarColumn(ColumnDescription = "名字")]
        public string Name { get; set; }

        /// <summary>
        /// 账号
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public string Account { get; set; }

        /// <summary>
        /// 密码
        /// </summary>
        [SugarColumn(ColumnDescription = "密码")]
        public string Password { get; set; }

        /// <summary>
        /// 手机
        /// </summary>
        [SugarColumn(ColumnDescription = "手机", IsNullable = true)]
        public string Phone { get; set; }

        /// <summary>
        /// 邮箱
        /// </summary>
        [SugarColumn(ColumnDescription = "邮箱", IsNullable = true)]
        public string Email { get; set; }

        /// <summary>
        /// 字典存储
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public string RoleId { get; set; }

        /// <summary>
        /// 部门
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public string DepartmentId { get; set; }

        [Navigate(NavigateType.ManyToOne,nameof(DepartmentId))]
        public Department Department { get; set; }

        /// <summary>
        /// 职位
        /// </summary>
        [SugarColumn(IsNullable = true)]
        public string JobId { get; set; }

        [Navigate(NavigateType.ManyToOne,nameof(JobId))]
        public Job Job { get; set; }


        [SugarColumn(Length = 18, ColumnDescription = "身份证号", IsNullable = true)]
        public string IdNum { get; set; }

        public override void Create(string creator)
        {
            Password = "123".MDString2();
            base.Create(creator);
        }

        /// <summary>
        /// 模型数据验证
        /// </summary>
        /// <returns></returns>
        public override (bool, string) Verify()
        {
            var msg = "";
            var result = true;

            if (!IdNum.MatchIdentifyCard())
            {
                result = false;
                msg += "身份号格式不正确!";
            }

            if (!Phone.MatchPhoneNumber())
            {
                result = false;
                msg += "手机号格式不正确!";
            }

            

            return (result, msg);
        }
    }
}